package com.nineclock.signIn.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.signIn.dto.SignInfoDTO;
import com.nineclock.signIn.dto.SignInfoListDTO;
import com.nineclock.signIn.service.SigInListService;
import com.nineclock.signIn.service.SigInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import java.io.IOException;

/**
 * @author : Liu
 * @date : 2021/12/1 0001 17:00
 */
@RestController
@RequestMapping
@Api(value = "签到管理接口", tags = "签到服务")
public class SignInController {
    @Autowired
    private SigInService sigInService;

    @Autowired
    private SigInListService sigInListService;

    /**
     * APP: 签到
     * 接口路径：POST/sign/insert
     */
    @ApiOperation("APP: 签到")
    @PostMapping("insert")
    public Result SignInAPP(SignInfoDTO signInfoDTO) {
        sigInService.SignInAPP(signInfoDTO);
        return Result.success();
    }

    /**
     * PC: 导出签到列表
     * 接口路径：GET/sign/export
     */
    @ApiOperation("PC: 导出签到列表")
    @GetMapping("export")
    public void export(@RequestParam String startTime, @RequestParam String endTime) throws Exception {
        sigInService.export(startTime, endTime);
    }

    /**
     * PC: 查询签到列表
     * 接口路径：GET/sign/sign
     */
    @GetMapping("sign")
    @ApiOperation("PC: 查询签到列表")
    public Result<PageResult<SignInfoListDTO>> querySignList(@RequestParam String endTime,
                                                             @RequestParam String startTime,
                                                             @RequestParam(defaultValue = "1") Long page,
                                                             @RequestParam(defaultValue = "10") Long pageSize){
        PageResult<SignInfoListDTO> pageResult = sigInService.querySignList(startTime,endTime,page,pageSize);
        return Result.success(pageResult);
    }

    /**
     * APP: 查询本月签到记录
     * 接口路径：GET/sign/pagingSignCurrentUserByMonth
     */

    @ApiOperation("APP: 查询本月签到记录")
    @GetMapping("/pagingSignCurrentUserByMonth")
    public Result<List<SignInfoDTO>> pagingSignCurrentUserByMonth(){
        List<SignInfoDTO> signInfoDTOList = sigInService.pagingSignCurrentUserByMonth();
        return Result.success(signInfoDTOList);
    }

    /**
     * APP: 获取当前用户当天签到次数
     * 接口路径：GET/sign/getDayCount
     */
    @ApiOperation("APP: 获取当前用户当天签到次数")
    @GetMapping("getDayCount")
    public Result<Integer> getDayCount() {
        int count = sigInService.getDayCount();
        return Result.success(count);
    }

/*
   /**
     * PC: 查询签到列表
     * 接口路径：GET/sign/sign
     *//*
    @ApiOperation("PC: 查询签到列表")
    @GetMapping("sign")
    public Result<PageResult<SignInfoListDTO>> signList(String endTime,
                                                    String startTime,
                                                    @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "7") Integer pageSize) {
        PageResult<SignInfoListDTO> List = sigInListService.signList(endTime,startTime,page,pageSize);
        return Result.success(List);
    }*/

    /**
     * PC: 导入签到列表
     * 接口路径：Post/sign/import
     */
    @ApiOperation("PC: 导入签到列表")
    @PostMapping("import")
    public Result importList(MultipartFile excelFile) throws Exception{
        sigInService.importList(excelFile);
        return Result.success();
    }


}
